﻿using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Moxiecode.TinyMCE.Settings;

namespace Moxiecode.TinyMCE.Web.Controls.Design
{
    public class TinyMCEDesigner : ControlDesigner
    {
        private static readonly string EmptyStyleFormat = "<table cellpadding=4 cellspacing=0 style=\"font:messagebox;color:buttontext;background-color:buttonface;border: solid 1px;border-top-color:buttonhighlight;border-left-color:buttonhighlight;border-bottom-color:buttonshadow;border-right-color:buttonshadow\"> <tr><td nowrap>{0}</td></tr><tr><td>{1}</td></tr></table>";

        public override bool AllowResize
        {
            get { return false; }
        }

        public TinyMCEDesigner() : base() { }

        public override string GetDesignTimeHtml()
        {
            string info = "<b>" + this.ID + "</b>";
            info += "<div style=\"font-size: 0.95em; margin-top: 2px; padding-top: 2px;\">";
            if (Component is TinyMCE)
            {
                TinyMCE comp = (TinyMCE)Component;
                info += "<b>Mode:</b> " + comp.Mode.ToString() + "<br />";
                if (comp.Mode == Mode.Exact && comp.Targets != null && comp.Targets.Count > 0)
                {
                    info += "<b>Targets:</b>";
                    info += "<ul style=\"padding:5px;margin:0px;margin-left: 15px;\">";
                    foreach (Target t in comp.Targets)
                    {
                        info += "<li>" + t.TargetID + "</li>";
                    }
                    info += "</ul>";
                }
                else if (comp.Mode == Mode.TextBoxes)
                {
                    info += "<b>Targets:</b> Non-extended TextBox controls.";
                }
            }
            info += "</div>";
            return String.Format(TinyMCEDesigner.EmptyStyleFormat, info, "");
        }
    }
}